<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: SXLWTT
  Date: 2021/10/21
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-1.9.1.min.js"></script>
    <script src="/js/fileupload.js"></script>
    <link rel="stylesheet" href="/css/css.css">
</head>
<body>

<table>
    <tr>
        <td colspan="11">
            <form action="/list.do" method="post">
                <input type="hidden" name="pageNum">
                标题：<input type="text" name="title" value="${map.title}">
                内容：<input type="text" name="content" value="${map.content}">
                标签查询：
                <select name="tid">
                    <option value="">请选择</option>
                </select>

                <input type="submit" value="查询">
            </form>
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" name="one" onclick="onee()">
        </td>
        <td>ID</td>
        <td>标题</td>
        <td>图片</td>
        <td>内容</td>
        <td>创建时间</td>
        <td>标签</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="li">
        <tr>
            <td>
                <input type="checkbox" name="two" value="${li.aid}">
            </td>
            <td>${li.aid}</td>
            <td>${li.title}</td>
            <td><img src="${li.pic}" width="80px">
                    </td>
            <td>${li.content}</td>
            <td>${li.createtime}</td>
            <td>${li.tnames}</td>
            <td>
                <input type="button" value="修改" onclick="updatee(${li.aid})">
                <input type="button" value="删除" onclick="del(${li.aid})">
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="11">
            <a href="javaScript:fuye(1)">首页</a>
            <a href="javaScript:fuye(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a>
            <a href="javaScript:fuye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a>
            <a href="javaScript:fuye(${pageInfo.pages})">尾页</a>
            <input type="button" value="批量删除" onclick="delAll()">
            <input type="button" value="添加" onclick="add()">
        </td>
    </tr>
</table>
</body>
</html>
<script>
    $.ajax({
        url:"listTag.do",
        type:"post",
        dataType:"json",
        success:function (obj) {
            for (var i in obj){
                console.log(obj[i])
                $("[name='tid']").append("<option value='"+obj[i].tid+"'>"+obj[i].tname+"</option>")
            }
        }
    })
    function delAll() {
        //批量删除
       var aaa= $("[name='two']:checked").map(function () {
            return $(this).val()
        }).get().toString()
        if (confirm("确认删除吗？")) {
            $.ajax({
                url:"delAll.do",
                data:{aid:aaa},
                type:"post",
                dataType:"json",
                success:function (obj) {
                    if (obj>0){
                        alert("删除成功")
                        location="list.do"
                    }
                }
            })
        }

    }
    function fuye(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit();
    }

    function onee() {
        $("[name='one']").change(function () {
            $("[name='two']").prop("checked",$(this).prop("checked"))
        })
    }
    function add() {
        location="toadd.do";
    }
//3.36
    function updatee(aid) {
        location="toupdate.do?aid="+aid;
    }
</script>
